<?php
/**
 * Created by PhpStorm.
 * User: Guangpen Chen
 * Date: 2014-12-20
 * Time: 16:45
 */

include '/var/www/html/new/com.inc.php';
include '/var/www/html/new/d/common/func.inc.php';
include '/var/www/html/new/d/class/MemberAccount.class.php';
/*连接数据库*/
require_once("/var/www/html/new/conf/le.je");
$le        = new go_sql();
$le->connect();
$data = file_get_contents('php://input');
$p_type    =array('景区'=>'A','路线'=>'B','酒店'=>'C','套票'=>'F','餐饮'=>'G','演出'=>'H');
$arr       = json_decode($data,true);
$sql_area  ="select * from pft_area_code_concat";
$GLOBALS['le']->query($sql_area);
/*搜索显示景区的信息，键值为景区id即lid*/
$r = array();
while($row=$GLOBALS['le']->fetch_assoc()) {
    $r[$row['province']][$row['city']]=$row;
}
$sql = "insert into pft_resource (title,p_type,tel,area,areacode,competitor,jtype,addtime) values";
foreach($arr as $arr_val ) {
    foreach($arr_val as $scenic) {
        if(strstr($scenic['area'],'省')) {
            $arr  = explode($scenic['area'],'省');
            $pre  = $arr[0].'省';
            $city = $arr[1];
        }
        else {
            $pre  = mb_substr($scenic['area'],0,2,'utf-8').'省';
            $city = mb_substr($scenic['area'],2,2,'utf-8').'市';
        }
        $jtype = $scenic['jtype'] > 0 ? $scenic['jtype'] : 0;
        $competitor = $scenic['competitor']=='无' ? '': $scenic['competitor'];
        $sql .= "('{$scenic['title']}','{$p_type[$scenic['p_type']]}','{$scenic['tel']}','{$r[$pre][$city]['s_code']}','{$r[$pre][$city]['n_code']}','{$competitor}','{$jtype}',NOW()),\n";

//        if(array_key_exists($pre,$r)) {
//            if(array_key_exists($city,$r[$pre])) {
//            }
//        }

//    $GLOBALS['le']->query($sql);
//    /*搜索显示景区的信息，键值为景区id即lid*/
//    while($row=$GLOBALS['le']->fetch_assoc())
//    {
//
//    }
    }
}
echo $sql;
exit;
$mem  = new \pft\Member\MemberAccount($GLOBALS['le']);

$idx = 0;
$mobiles = array();
//print_r(array_shift($arr));
//exit;
foreach ($arr->Sheet1 as $k=>$v) {
    if (!is_numeric($v->mobile)) {
        continue;
    }
//    $mobiles[] = $v->mobile;
    $sql_chk = "SELECT id FROM pft_member WHERE mobile='{$v->mobile}' LIMIT 1";
    $idx += 1;
    $GLOBALS['le']->query($sql_chk);
    $row = $GLOBALS['le']->fetch_assoc();
    if ($row['id']) {
        $res[] = $mem->createRelationship($parent_id, $row['id']);
    } else {
        $fid = $mem->mobileRegister($v->mobile, 1, str_replace('\r','',$v->name));
        $res[] = $mem->createRelationship($parent_id, $fid);
    }

    echo $v->name . '--' . $v->mobile . PHP_EOL;
}
//$res = array();
//foreach ($fids as $fid) {
//    $res[] = $mem->createRelationship($parent_id, $fid);
//}
print_r($res);